This page allows you to get the color of a pixel clicked on anywhere on the screen.
The page script for this page contains all of the handlers. The enterPage handler links to USER, KERNEL, GDI, and TBKWIN for functions that will be used to determine which pixel was clicked on and what the RGB and HLS values are for that pixel.
When the page or background is clicked a buttonUp handler minimizes the ToolBook window, translates the left mouse button up message from windows and captures all mouse and keyboard input to ToolBook. When ToolBook gets a WM_LBUTTONUP message from windows it sends the message to this page, which determines which pixel was clicked on and fills out the fields and sets the fillcolor of the rectangle.
To use the demo, just click anywhere on the page to minimize ToolBook, then click on the pixel whose RGB and HLS value you want. ToolBook will automatically restore itself and the value for the pixel will be displayed in the fields.
The script is heavily commented so I will refer you there for a more detailed explanation.
0,255,05555
color
120,50,1000100
R G B
H L S
Title
Chapter Name
buttonUp
buttonUp
buttonUp
buttonUp
buttonUp
Get pixel in ToolBook window
ToolBook
Clicking the left mouse button in the ToolBook window causes the RGB and HLS fields to be updated and the fillColor of the rectangle to be set to the color of the pixel that was clicked on. Because ToolBook objects can only use the system colors, the rectangle may be dithered if you choose a pixel from the windsurfer graphic.
The enterPage script for this page links the GDI function: GetPixel(), the TBKWIN DLL functions: RGBtoHLS() and ClientFromPage(), and the USER function GetDC().
The page handles the buttonUp message where it translates the page unit into screen units and calls GetPixel() with the point that was clicked on. It then extracts the red, green, and blue values from the return value and sets the text of the fields.
The background script sends the buttonUp message back to the page because there are recordfields on the page.
To use the example click anywhere on the ToolBook page and watch the fields and rectangle change. the ToolBook page and watch the fields and rectangle change. .
160,160,16435
color
240,63.5,2.18758755
:PHYSSIZE
:PHYSSIZE
4hPointStruct, lpPointStruct
--Standard stuff
BBS template
" > 0
--End Standare
linkDLL USER
INT ClientToScreen(WORD,POINTER)
GetWindowDC(
5GetWindowRect(
7 GetParent(
]ReleaseCapture()
rReleaseDC(
s SetCapture(
ScreenToClient(
ShowWindow(
WindowFromPoint(DWORD)
GetMessagePos()
( GetPixel(
KERNEL
M GlobalAlloc(
GlobalLock(
x GlobalUnlock(
GlobalFree(
"TBKWIN.DLL"
STRING RGBtoHLS(
--Allocate memory
Structures
68, 12)
--Hide the ToolBook
allow access
screen
--Translate
Smouse
Bup messages that
Send
tuser defined
/ WM_LBUTTONUP
gets
translateWindowMessage
--Tell Windows
keyboard
setCapture(
was sent
coords.
--(I didn't
lParam because
relative
screenCoords
takes
value
sturcture,
--The point structure
just a
loword
hiword.
This
same
returns - how convinent.
--We want
topmost
so we walk
--out
nested child windows.
hWnd
--Get
Device Context
whole
you can choose
title bar
--User
function
convert
coordinates given
Coordinates
upper
Scorner
clicked.
screenToWindow(
pixel
--If
clipping region
specified DC
--Take appart
COLORREF
returned
4294967295 -- 0xFFFFFFFF
redValue
k256 --
lobyte
y256 --
bits 8
greenValue
k256 --
y256 --
blueValue
HLSValue
= -20
+ conversion failed "
"RGB"
&","&
&","&
"color"
--Clean up
, hDC)
untranslateWindowMessage 514
allocated
ScreenToWindow
xWinCoords
pointerINT(0,
yWinCoords
pointerDWORD(0,
, 0)
xClientCoords
yClientCoords
xOffset
yOffset
xCoord
yCoord
buttonUp
enterPage
WM_LBUTTONUP
leavePage
ScreenToWindow
enterPage
ClientToScreen
GetWindowDC
GetWindowRect
GetParent
ReleaseCapture
ReleaseDC
SetCapture
ScreenToClient
ShowWindow
WindowFromPoint
GetMessagePos
GetPixel
GlobalAlloc
GlobalLock
GlobalUnlock
GlobalFree
TBKWIN.DLL
RGBtoHLS
GlobalAlloc
GlobalLock
KERNEL
hPointStruct
lpPointStruct
buttonUp
ShowWindow
WM_LBUTTONUP
setCapture
WM_LBUTTONUP
GetMessagePos
WindowFromPoint
GetParent
GetWindowDC
screenToWindow
GetPixel
RGBtoHLS
RGB to HLS conversion failed
color
ReleaseDC
ReleaseCapture
ShowWindow
HLSValue
blueValue
greenValue
redValue
screenCoords
leavePage
GlobalUnlock
GlobalFree
hPointStruct
ScreenToWindow
GetWindowRect
ClientToScreen
ScreenToClient
yCoord
xCoord
yOffset
xOffset
yClientCoords
xClientCoords
yWinCoords
xWinCoords
lpPointStruct
screenCoords
--Standard stuff
BBS template
" > 0
linkDLL USER
WORD GetDC(
INT ReleaseDC(
DWORD GetPixel(
_"TBKWIN.
STRING RGBtoHLS(
ClientFromPage(
, sysMagnification,
xCoord
yCoord
sysClientHandle)
<> -1
redValue
k256 --
the lobyte
y256 --
bits 8
greenValue
k256 --
y256 --
blueValue
that's
6value
HLSValue
= -20
"RGB
, conversion failed "
&","&
&","&
"color"
, hDC)
enterPage
buttonUp
enterPage
GetDC
ReleaseDC
GetPixel
TBKWIN.DLL
RGBtoHLS
ClientFromPage
buttonUp
ClientFromPage
GetDC
GetPixel
RGBtoHLS
RGB to HLS conversion failed
color
ReleaseDC
HLSValue
blueValue
greenValue
redValue
yCoord
xCoord
Banner
Disclaimer
The files from Asymetrix Corporation On-line services are made available for demonstration and experimentation purposes, but they are not official Asymetrix products. As such, they are not subject to our usual high standards of documentation or product review. Feedback is welcome. Please send your questions or comments to the Asymetrix BBS sysop. Asymetrix does not provide phone support for these examples.
This book and example scripts are Copyright Asymetrix Corporation. Asymetrix gives you permission to copy, revise and reuse the individual objects and scripts in this application in your own applications. Include the notice "Portions of this application are the copyright of Asymetrix Corporation" in your product if they contain objects or scripts copied from this application. You may not copy the entire book (or a substantial part of it) for redistribution as your own product.w
Settings are: NO parity, 1 stop bit, and 8 data bits.
:PHYSSIZE
Book Title
Get Pixel
buttonUp
buttonUp
ttvltt
lltvvt
vvtlttvt
tltlv
llttl
ltlvttl
lvvtlt
ccvllc
lvltltv
cldvtlltlt
ttclvltv
AVllctt
lltll
cltll
llVcV
ttlltl
lcVcl
vvVlVlj
lvcll
vlcVlVcVlV
tlvlt
VlVlcll
@cdcl
vlltlltcll
lc:VV
tVltVlcl
llcctc
lvlclv
@@Vll
tlclc
clvllvltlt
tvllvlt
VlltVllv
Vllclcttvv
lctlt
tclltvld
YYXXY
XmX2XXm
YYXG2GdLGX
mG3318K
mm2LX
Gm2L22XL22
G2GL2LL2L"
PXXIIY
XGmmGm
mmYGGHYXmm
GGLmLL
O2GXGX
G2"XXG2G
2mGXGG
mGwXmm
2LLGwGXXmm
8GGXX
vdGIIYSY
@@j@j
mXww88
LXwGG
PPjP@m
ww8mw88
GIHHIm
jPjjPPj
w88ww88
"2Gm2
22P@jP@
"L22"
IIHIXd
A@VP@VdldV
5ddjPLP@@:
PddPV
83IIHHLd
@lPOSSGG
3IIHHG
mHIIHIX
A22"
8^^8^
Y/3IIYm
GSS2S
mmYY2
/GGHG5GH5
wL" 8
/IIHHm2
GH5H5H
mXXL88
IHI5GH/
md"Add2m
/GG/G
GG/ G
>A@"8""
""Adw^
mXm2mw
mA"Vlw8"
G/G/GG/
L@"@d
P
3G//HG/
/G/G/
1/G2S
GGYIHH/
8K1%/1
YYGGYH
HGIHHYYX
mII/I
35GGH
13K311
^8 88
wsK88"
XX8"P
wXGXX
wwKX%11
w8w8 "P
"88228
GXX2Pmmww
88XX
m5IHH
wXXKwX88
X8K811
YYGYG2A^^
811KKssww
mHIHH
KKX883Kw
8"8 "8Kss
YYXXm2d
XYGX2
GGXX
2 88
mHIHI
mG22P
YHHYY
YHHGY
mHHY2
mYHHG2G2G2
mGHYXXGG2
mH/GX
H5XXKXXw
ist boxes
color
Get pixel in ToolBook window
ToolBook
Clicking the left mouse button in the ToolBook window causes the RGB and HLS fields to be updated and the fillColor of the rectangle to be set to the color of the pixel that was clicked on. Because ToolBook objects can only use the system colors, the rectangle may be dithered if you choose a pixel from the windsurfer graphic.
The enterPage script for this page links the GDI function: GetPixel(), the TBKWIN DLL functions: RGBtoHLS() and ClientFromPage(), and the USER function GetDC().
The page handles the buttonUp message where it translates the page unit into screen units and calls GetPixel() with the point that was clicked on. It then extracts the red, green, and blue values from the return value and sets the text of the fields.
The background script sends the buttonUp message back to the page because there are recordfields on the page. Messages passing up the heirarchy go to the parent of the object next and the parent of a recordField is the background.
To use the example click anywhere on the ToolBook page and watch the fields and rectangle change.